using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Web.UI;
using System.Web.UI.WebControls;

using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Services.Localization;

namespace Jfc.DnnMarketingTools.MemberInvite
{
    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The ViewMemberInvite class displays the content
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// </history>
    /// -----------------------------------------------------------------------------
    partial class ViewMemberInvite : PortalModuleBase, IActionable
    {

        #region Public Methods

        public bool DisplayAudit()
        {
            bool retValue = false;

            if ((string)Settings["auditinfo"] == "Y")
            {
                retValue = true;
            }

            return retValue;
        }

        #endregion

        #region Event Handlers

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the control is loaded
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                if (!Page.IsPostBack)
                {
                    MemberInviteController objMemberInvites = new MemberInviteController();
                    List<MemberInviteInfo> colMemberInvites;

                    //get the content from the MemberInvite table
                    if( UserInfo.IsSuperUser)
                        colMemberInvites = objMemberInvites.GetMemberInvites(PortalId);
                    else
                        colMemberInvites = objMemberInvites.GetMemberInvitesForUser(PortalId,UserId);

                    //Localize the Data Grid
                    Localization.LocalizeDataGrid(ref grdMemberInvites, LocalResourceFile);

                    grdMemberInvites.DataSource = colMemberInvites;
                    grdMemberInvites.DataBind();
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }

        }


        /// -----------------------------------------------------------------------------
        /// <summary>
        /// cmdUserSettings_Click runs when the UserSettings button is clicked
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        protected void cmdUserSettings_Click(System.Object sender, System.EventArgs e)
        {
            try
            {
                this.Response.Redirect(Globals.NavigateURL(TabId, "UserSettings"));

            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        #endregion

        #region Optional Interfaces

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Registers the module actions required for interfacing with the portal framework
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public ModuleActionCollection ModuleActions
        {
            get
            {
                ModuleActionCollection Actions = new ModuleActionCollection();

                Actions.Add(this.GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, this.LocalResourceFile), ModuleActionType.AddContent, "", "", this.EditUrl(), false, SecurityAccessLevel.Edit, true, false);
                Actions.Add(this.GetNextActionID(), Localization.GetString("UserSettings.Action", this.LocalResourceFile), ModuleActionType.AddContent, "", "", this.EditUrl("UserSettings"), false, SecurityAccessLevel.Edit, true, false);

                return Actions;
            }
        }

        #endregion

        protected string DisplayName(string firstName, string lastName)
        {
            if (String.IsNullOrEmpty(lastName))
                return firstName;

            return firstName + " " + lastName;
        }

        protected string DisplayDate(DateTime dateTime)
        {
            return dateTime.ToString();
        }
    }
}

